package com.njtoyo.taxi.admin.rest.controller.business.operation_rule;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.RealTimeCallRulePresenter;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.SimpleCallInfoServiceFeeRulePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.RealTimeCallRuleUpdateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.RealTimeCallRuleWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.call_prepay_rule.CallPrepayRuleAddUpdateWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.RealtimeCallRuleService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 发单规则
 */
@RestController
@RequestMapping("/business/operation-rule/realtime-call-rule")
public class RealtimeCallRuleController {
    @Autowired
    private RealtimeCallRuleService realtimeCallRuleService;


    @GetMapping("/list")
    RestResult<IPage<RealTimeCallRuleWrapper>> list(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                                                    @RequestParam(value = "size", required = false, defaultValue = "15") Integer size,
                                                    @RequestParam(value = "driverRegionName", required = false) String driverRegionName) {
        IPage<RealTimeCallRuleWrapper> page = realtimeCallRuleService.getPage(current, size, driverRegionName);
        return RestResult.success(page);
    }


    //    @PostMapping("/update")
//    public RestResult add(@RequestBody RealTimeCallRulePresenter presenter) {
//        if(ObjectUtil.isNull(presenter.getCallGapTimes())||ObjectUtil.isNull(presenter.getCallGapSecond())||ObjectUtil.isNull(presenter.getCallGapDistance())){
//            return RestResult.failed("缺少参数");
//        }
//        return realtimeCallRuleService.update(presenter);
//    }
//
    @GetMapping("/{id}/detail")
    public RestResult getDetail(@PathVariable("id") Long id) {
        return realtimeCallRuleService.getDetail(id);
    }

    @PostMapping("/updateById")
    public RestResult updateById(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @RequestBody RealTimeCallRuleUpdateWrapper wrapper) {
        if (ObjectUtil.isNull(wrapper.getCallGapDistance()) || ObjectUtil.isNull(wrapper.getCallGapTimes()) || ObjectUtil.isNull(wrapper.getCallGapSecond())) {
            return RestResult.failed("缺少参数");
        }
        return realtimeCallRuleService.updateById(adminUser,wrapper);
    }
}
